<template>
  <div class="app-container">
    <!-- 查询框 -->
    <div class="filter-container">
      <el-input
        v-model="pageParam.superSearchKeyWord"
        style="width: 200px;"
        placeholder="关键字查询..."
        class="filter-item"
        @keyup.enter.native="handleFilter"
        @input="handleFilter"
      />
    </div>

    <!-- 表格 -->
    <el-table :data="list" fit highlight-current-row style="width: 100%;" @sort-change="sortChange">

      <!-- 表格字段 -->
      <el-table-column prop="orderNo" label="退药单号" />
      <el-table-column prop="realName" label="病人" />
      <el-table-column prop="drawbackReason" label="退药原因" />
      <el-table-column prop="drawbackMoney" label="退药金额" />
      <el-table-column prop="createTime" label="退药时间" width="200px" />

      <el-table-column label="操作" fit width="300px">
        <template slot-scope="{row,$index}">
          <el-button v-if="row.status==0" size="small" type="success" @click="handelmedicinalSure(row)">
            确认退药
          </el-button>
          <el-button v-if="row.status==0" size="small" type="danger" @click="handelmedicinalFuse(row)">
            驳回
          </el-button>
          <el-button v-if="row.status==1" disabled="disabled" size="small" type="success" @click="handelRecipelSure(row.id)">
            已退药
          </el-button>
          <el-button v-if="row.status==10" disabled="disabled" size="small" type="danger" @click="handelRecipelSure(row.id)">
            已驳回
          </el-button>
        </template>
      </el-table-column>

    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.pageSize"
      @pagination="getListByPage"
    />

  </div>
</template>

<script>
import {
  mapGetters,
  mapState
} from 'vuex'

import {
  getToken
} from '@/utils/auth'

import {
  searchSomeMedicinalPage,
  medicinalSure,
  medicinalFuse
} from '@/api/medicinal/drawbackMedicinal'

// 导入组件  记得声明组件
import Pagination from '@/components/Pagination'

export default {
  components: { // 在这里声明组件
    Pagination
  },
  data() {
    return {
      dialogVisible: false,
      list: [], // 列表数据
      total: 0,
      listQuery: { // 分页 排序  查询参数
        pageNum: 1,
        pageSize: 5
      },
      fieldQuery: { // 按字段查询
        realName: ''
      },
      dialogFormVisible: false,
      MedicinalVisible: false,
      dialogStatus: '',
      dialogPvVisible: false,
      pvData: [],
      temp: {
        id: '',
        patientId: '',
        drawbackReason: '',
        orderNo: '',
        drawbackMoney: '',
        createTime: '',
        status: '',
        realName: ''
      },
      rules: {},
      pageParam: {
        pageNum: 1,
        pageSize: 6,
        model: {},
        orderParams: [],
        superSearchKeyWord: ''
      },
      categoryId: '',
      recipelId: '',
      roleList: []
    }
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill
    }
  },
  created() {
    this.getListByPage()
  },
  methods: {
    handelmedicinalSure(row) {
      medicinalSure(row).then((res) => {
        this.$notify({
          title: '成功',
          message: '退药成功',
          type: 'success',
          duration: 2000
        })
        this.getListByPage()
      })
    },
    handelmedicinalFuse(row) {
      medicinalFuse(row).then((res) => {
        this.$notify({
          title: '成功',
          message: '核对成功',
          type: 'success',
          duration: 2000
        })
        this.getListByPage()
      })
    },
    sortChange(val) {
      // console.log("排序参数",val)
      const prop = val.prop
      const order = val.order === 'ascending' ? 'asc' : 'desc'
      const orderParam = prop + ' ' + order
      // console.log(orderParam)
      for (let i = 0; i < this.pageParam.orderParams.length; i++) {
        if (this.pageParam.orderParams[i].indexOf(prop) > -1) {
          this.pageParam.orderParams.splice(i, 1)
        }
      }
      this.pageParam.orderParams.push(orderParam)
      console.log(this.pageParam.orderParams)
      this.getListByPage()
    },
    getListByPage() {
      this.pageParam.pageNum = this.listQuery.pageNum
      this.pageParam.pageSize = this.listQuery.pageSize

      console.log(this.pageParam.orderParams)

      searchSomeMedicinalPage(this.pageParam).then(res => {
        // console.log("列表数据" + JSON.stringify(res.content.list.recipelChild));
        this.list = res.content.list
        this.total = res.content.total
      }).catch(err => {
        console.log(err)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getListByPage()
    },
    resetTemp() {
      this.temp = {
        id: '',
        patientId: '',
        drawbackReason: '',
        orderNo: '',
        drawbackMoney: '',
        createTime: '',
        status: '',
        realName: ''
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)

      const imageUrl = file.response == undefined ? file.url.replace('blob:', '') : file.response.content
      // let imageUrl = ''
      const productImageData = {
        imageUrl: imageUrl
      }
      deleteSomeProductimageTrueByCondition(productImageData).then(() => {
      })
    },
    onEditorBlur(quill) {
      // console.log('editor blur!', quill)
    },
    onEditorFocus(quill) {
      // console.log('editor focus!', quill)
    },
    onEditorReady(quill) {
      // console.log('editor ready!', quill)
    },
    onEditorChange({
      quill,
      html,
      text
    }) {
      // console.log('editor change!', quill, html, text)
      this.temp.description = html
    }
  }
}
</script>

<style>
  .demo-table-expand {
    font-size: 0;
  }

  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }

  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
